<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="zh">
<jsp:include page="/templates/head.jsp"></jsp:include>
<body>
	<jsp:include page="/templates/nav.jsp"></jsp:include>

	<div class="main"${user==null?"hidden='hidden'":"" }>
		<jsp:include page="/templates/menu.jsp"></jsp:include>
		
		<div class="main-right">
			<div class="panel">
				<div class="panel-desc">
					<span class="main-nav-active"> 
						<a href="/stuscore/">
							首页
						</a>
					</span>
					<span class="main-nav-sep"> 
						/ 
					</span>
					<span class="main-nav-active">
						<a href="/stuscore/exam?action=page&pageIndex=1&pageSize=10">考试信息管理</a> 
					</span>
					<span class="main-nav-sep"> 
						/ 
					</span>
					<span class="main-nav-this">
						编辑考试信息
					</span>
				</div>
			</div>

			<div class="panel">
				<div class="panel-title">成绩查询</div>

				<div class="panel-desc">
					<form action="" class="search" method="get">
						<div>
						
							<span class="search-label"> 学生姓名： </span> 
							<input type="text" class="search-input" />
							<input type="hidden" name="gid" value="${exam.gid }">
							<input type="hidden" name="eid" value="${exam.id }">
						</div>
						<div class="search">
							<button type="button" class="btn btn-search">
								<span class="fa fa-search"></span>
							</button>
						</div>
					</form>
				</div>
			</div>

			

			<div class="panel">
				<label >点击学号或成绩进行排序！</label>
				<br/><br/>
					<label>当前科目：<strong>${pname }</strong></label>
				<br/>
				
				<div class="panel-desc">
					<table class="table-data" id="myTable">
						<thead>
							<tr>
								<td>序号</td>
								<td>学生姓名</td>
								<th style="cursor: pointer;" onclick="sortTable(2)">学号</th>
								
								<td>班级</td>
								<td>考试名称</td>
								<th style="cursor: pointer;" onclick="sortTable(5)">考试成绩</th>
								<td>修改/录入</td>
							</tr>
						</thead>

						<tbody>
							<c:forEach var="student" items="${students}" varStatus="index">
								<tr>
									<td>${index.index+1 }</td>
									<td>${student.name}</td>
									<td>${student.id }</td>
									<td>${student.gname }</td>
									<td>${exam.name }</td>
									<td >
										${student.score==null?'':student.score }
										
									</td>
									<td >
										
										<input type="text" name = "score" value="${student.score==null?'':student.score }">
										<input type="hidden" name="sid" value="${student.id}">
									</td>
									
								</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
			</div>

			<div class="page-panel">
				<div class="page-panel-desc">
					<%-- 共${page.count }条数据，每页${page.pageSize }条，第${page.pageIndex }页 --%>
					<button id="sub" value="" class="editscore">提交</button>
				</div>
			</div>

		</div>
	</div>
	
	<jsp:include page="/templates/foot.jsp"></jsp:include>
	
	<script type="text/javascript" src="/stuscore/js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript" src="/stuscore/js/myJs.js"></script>
	<script type="text/javascript">
	var sIds=new Array();
	var scores=new Array();
	var eId;
	/* 服务器IP地址 */
	var serverIp="110.42.131.149";
	$(".btn-search").on("click",function(e){
		var qryText=$(".search-input").val(),
			gId=$("input[name=gid]").val(),
			eId=$("input[name=eid]").val();
		
		
		
		window.location.href="/stuscore/exam?action=scoreView&name="+qryText+"&eid="+eId+"&gid="+gId;
		
	}); 
	
	
	$(".editscore").on("click",function(){
		sIds=new Array();
		scores=new Array();
		eId=null;
		
		eId=$("input[name=eid]").val();
		$("table tr").each(function(i,item){
			var sid = $(item).find("input[name=sid]").val(),
				score = $(item).find("input[name=score]").val();
			if (score=="") {
				score=0;
			}
					
			if (!isNaN(score)) {
				sIds.push(sid);
				scores.push(score);
			} 
		})
		
		$.ajax({
			url:"http://"+serverIp+":8080/stuscore/score",
			data:{
				action: "edit",
				sIds:sIds,
				scores:scores,
				eId:eId
			},
			success:function(e){
				window.location.href="/stuscore/exam?action=page&pageIndex=1&pageSize=10";
			}
		});
	});
	
		
		
		
	</script>
</body>
</html>